<?php

namespace Admin\Controller;

/**
 * 数据采集申请 控制器
 * 
 * @author BoBo
 *
 */
class ApplyUsersController extends CommController {
	public $model;
	/**
	 * 构造函数
	 */
	public function _initialize() {
		parent::_initialize ();
		// 模型
		$this->model = D ( 'Apply' );
		// 参数
		$this->paramter ['pid'] = I ( 'request.pid', 0 );
	}

	/**
	 * 修改一条数据
	 */
	public function update() {
		$modelName = I('post.model');
		$refresh = $_POST ['refresh'] ? $_POST ['refresh'] : 'refreshClose';
		$return = $this->model->commUpdate ( $_POST );
		$this->dwzSuccess ( $return ['info'], $return ['status'], $modelName, $refresh );
	}

	/**
	 * 删除一条或一组数据(伪删除)
	 */
	public function remove() {
		$idList = I ( 'post.id' );
		$return = $this->model->commRemove ( $idList );
		$this->dwzSuccess ( $return ['info'], $return ['status'], 'applyList', "refreshThis" );
	}

	/**
	 * 设置一条或一组数据的状态
	 */
	public function check() {
		$idList = I ( 'post.id' );
		$return = $this->model->commSetStatus ( $idList, array('status',1) );
		$this->dwzSuccess ( $return ['info'], $return ['status'], 'applyList', "refreshThis" );
	}
	
	/**
	 * 申请列表
	 */
	public function applyList() {
		// 设置查询条件
		$sql = "select * from tm_apply where is_delete = 0";
		if ( $search['status'] = (int)I('post.status', 0) ) {
			// 姓名
			$status = $search['status']-1;
			$sql .= " and status = {$status}";
		}
		
		// 真实姓名
		if ( $search['username'] = (string)I('post.username', '') ) {
			$sql .= " and username like '%{$search['username']}%'";
		}
		
		// 真实姓名
		if ( $search['checktime'] = (string)I('post.checktime', '') ) {
			$sql .= " and addtime >= '{$search['checktime']} 00:00:00' and addtime < '{$search['checktime']} 23:59:59'";
		}

		// 读取数据
		$this->dataList = $this->getPageSQLList( $this->model, $sql, 20, 'addtime desc');
		$this->assign ( 'dataList', $this->dataList );
		$this->assign ( 'search', $search );
		// 渲染模板
		$this->display ( 'Apply/index' );
	}
}